 

void (function( window, document, undefined ) {
	
	if (!(typeof ScBase != 'undefined' && ScBase)) {
	
		var ScBase = window.ScBase = {};

		/**
		 * 调用二手车焦点图
		 *
		 * @param {object} setting
		 * @return {null}
		 */
		ScBase.focus = function(setting){
			var self = this;
			var fImg = new self.focusImg(setting);
		}
		
		
		/**
		 * 焦点图函数
		 *
		 * @param {object} focusSrc 焦点图参数
		 * @return {null}
		 */
		ScBase.focusImg = function(setting){
		
			//大图规格
			this.imgBigWidth = setting.imgBigWidth || '240';
			this.imgBigHeight = setting.imgBigHeight || '160';
			//小图规格
			this.imgLitWidth = setting.imgLitWidth || '60';
			this.imgLitHeight = setting.imgLitHeight || '40';
			//鼠标切换图片事件
			this.mouseAction = setting.mouseAction ||'hover';
			//模型盒名称
			this.wrapLit = setting.wrapLit || 'fzxa-lit-wrap';
			this.wrapLitImg = setting.wrapLitImg || 'fzxa-lit-img';
			this.wrapBigImg = setting.wrapBigImg || 'fzxa-big-img';
			//左右移动
			this.btnLeft = setting.btnLeft || 'fzxa-btn-left';
			this.btnRight = setting.btnRight || 'fzxa-btn-right';
			//图片路径
			this.imgLitSource = setting.imgLitSource || '';
			this.imgBigSource = setting.imgBigSource || '';
			//播放时间
			this.focusTime = setting.focusTime || '100';
			//小图显示个数
			this.focusCount = setting.focusCount || '3';
			//创建图片
			this.focusImg();
			//自定义事件
			this.bind();

		}
		
		
		/**
		 * 创建图片列表
		 * @return {null}
		 */
		ScBase.focusImg.prototype.focusImg = function(){
			
			var self = this;
			//小图列表
			_createLitImg();
			function _createLitImg(){
				var len = self.imgLitSource.length;
				var html = '';
				var nowclass = '';
				if(len > 0){
					for(var i=0; i<len; i++){
						i == 0 ? nowclass = 'cur' : nowclass = '';
						html += '<li class="'+nowclass+'"><div class="vgcon"><div class="vgbox"><a href="javascript:;" class="abox"><img width="'+self.imgLitWidth+'" height="'+self.imgLitHeight+'" src="'+self.imgLitSource[i]+'" class="boxc"></a></div></div></li>';
					}
					$('#'+self.wrapLitImg).html(html);
				}
			}
			
			//首个大图
			if(self.imgBigSource.length > 0){
				var html = '<img width="'+self.imgBigWidth+'" height="'+self.imgBigHeight+'" src="'+self.imgBigSource[0]+'" />';
				$('#'+self.wrapBigImg).html(html);
			}
		}
		
		
		/**
		 * 自定义监听事件
		 * @return {null}
		 */
		ScBase.focusImg.prototype.bind = function(){
		
			var self = this;
			
			//@todo 鼠标经过小图替换大图
			$('#'+this.wrapLitImg).delegate("li", this.mouseAction, function(el){
				
				//清除当前状态，并增加选中状态
				_clearMouse(this);
				function _clearMouse(el){
					$('#'+self.wrapLitImg).children('li').removeClass('cur');
					$(el).addClass('cur');
				}
				
				//替换大图
				var no = $(this).index();
				$('#'+self.wrapBigImg).children('img').attr('src',self.imgBigSource[no]);
			});

			
			//@todo 右滚动
			$('#'+this.btnRight).bind('click', function(){
				if(true == self.checkDisabled('right')){
					var wrap = $('#'+self.wrapLitImg);
					var _w = $('#'+self.wrapLitImg).children('li').width();
					var _newleft = parseInt(wrap.css('left'),10);
					var w = _newleft-_w;
					wrap.animate({ 
						left: w
					  }, self.focusTime );
				}
			});
			
			//@todo 右滚动
			$('#'+this.btnLeft).bind('click', function(){
				if(true == self.checkDisabled('left')){
					var wrap = $('#'+self.wrapLitImg);
					var _w = $('#'+self.wrapLitImg).children('li').width();
					var _newleft = parseInt(wrap.css('left'),10);
					var w = _newleft+_w;
					wrap.animate({ 
						left: w
					  }, self.focusTime );
				}
			});
		}
		
		/**
		 * 检测是否可点
		 * @param {string} type 左右类型 left/right
		 * @return {null}
		 */
		ScBase.focusImg.prototype.checkDisabled = function(type){
			
			var self = this;
			var w = $('#'+self.wrapLitImg).children('li').width();
			var _tc = $('#'+self.wrapLitImg).children('li').length;
			_tc = _tc - this.focusCount;
			w = _tc * w;
			
			var nowleft = parseInt($('#'+self.wrapLitImg).css('left'),10);
			
			if(type == 'right'){
				return _checkRight();
			}else{
				return _checkLeft();
			}
			
			//检测右边
			function _checkRight(){
				var _tw = -w;
				if(nowleft  <= _tw){
					$('#'+self.btnRight).attr('class','nextno');
					return false;
				}else{
					$('#'+self.btnLeft).attr('class','pre');
					return true;
				}
			}
			//检测左边
			function _checkLeft(){
				if(nowleft  >= 0){
					$('#'+self.btnLeft).attr('class','preno');
					return false;
				}else{
					$('#'+self.btnRight).attr('class','next');
					return true;
				}
			}
		}
		

		
	}
	
})(this, this.document);
